package com.wc.AlgoOJ.CT0211;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/24 19:47
 * @description
 */
public class Main2 {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 20000;
    static long[] a;
    static int aLen;
    static int bLen;
    static long[] b;
    static int t, n, m, aa, bb;

    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            a = new long[N];
            b = new long[N];
            a[0] = 1;
            b[0] = 1;
            aLen = 1;
            bLen = 1;

            n = sc.nextInt();
            m = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                aa = sc.nextInt();
                for (int j = 0; j < aLen; j++) {
                    a[j] *= aa;
                }
                for (int j = 0; j < aLen; j++) {
                    a[j + 1] += a[j] / 10;
                    if (a[j + 1] > 0) {
                        aLen = Math.max(aLen, j + 2);
                    }
                    a[j] %= 10;
                }
                if (a[aLen - 1] >= 10) {
                    int j = aLen - 1;
                    while (a[j] >= 10) {
                        a[j + 1] += a[j] / 10;
                        a[j] %= 10;
                        j++;
                    }
                    aLen = j;
                }
            }
            for (int i = 1; i <= m; i++) {
                bb = sc.nextInt();
                for (int j = 0; j < bLen; j++) {
                    b[j] *= bb;
                }
                for (int j = 0; j < bLen; j++) {
                    b[j + 1] += b[j] / 10;
                    if (b[j + 1] > 0) {
                        bLen = Math.max(bLen, j + 2);
                    }
                    b[j] %= 10;
                }
                if (b[bLen - 1] >= 10) {
                    int j = bLen - 1;
                    while (b[j] >= 10) {
                        b[j + 1] += b[j] / 10;
                        b[j] %= 10;
                        j++;
                    }
                    bLen = j;
                }
            }
            if (aLen < bLen) {
                out.println('<');
            } else if (aLen > bLen) {
                out.println('>');
            } else {
                for (int j = aLen; j >= 0; j--) {
                    if (a[j] > b[j]) {
                        out.println('>');
                        break;
                    } else if (a[j] < b[j]) {
                        out.println('<');
                        break;
                    }
                }
            }
        }
        out.flush();
    }

    static class FastReader {
        StringTokenizer st;
        BufferedReader br;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        // 是否由下一个
        boolean hasNext() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = br.readLine();
                    if (line == null)
                        return false;
                    st = new StringTokenizer(line);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return true;
        }
    }
}
